package com.ruoyi.ly.service.impl;

import java.util.List;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ly.mapper.LyMerchantActivitiesMapper;
import com.ruoyi.ly.domain.LyMerchantActivities;
import com.ruoyi.ly.service.ILyMerchantActivitiesService;

/**
 * 商家活动Service业务层处理
 * 
 * @author liuyan
 * @date 2025-05-13
 */
@Service
public class LyMerchantActivitiesServiceImpl implements ILyMerchantActivitiesService 
{
    @Autowired
    private LyMerchantActivitiesMapper lyMerchantActivitiesMapper;

    /**
     * 查询商家活动
     * 
     * @param id 商家活动主键
     * @return 商家活动
     */
    @Override
    public LyMerchantActivities selectLyMerchantActivitiesById(Long id)
    {
        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesById(id);
    }

    //    多表查询
    @Override
    public LyMerchantActivities selectLyMerchantActivitiesByIds(Long id) {
        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesByIds(id);
    }
//test
//    @Override
//    public LyMerchantActivities selectLyMerchantActivitiesByIdss(Long mid) {
//        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesByIdss(mid);
//    }

    /**
     * 查询商家活动列表
     * 
     * @param lyMerchantActivities 商家活动
     * @return 商家活动
     */
    @Override
    public List<LyMerchantActivities> selectLyMerchantActivitiesList(LyMerchantActivities lyMerchantActivities)
    {
        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesList(lyMerchantActivities);
    }
    // <!--商家查询自己已上架的活动-->
    @Override
    public List<LyMerchantActivities> selectLyMerchantActivitiesList1(LyMerchantActivities lyMerchantActivities) {
        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesList1(lyMerchantActivities);
    }

    //    未上架
    @Override
    public List<LyMerchantActivities> selectLyMerchantActivitiesList2(LyMerchantActivities lyMerchantActivities) {
        return lyMerchantActivitiesMapper.selectLyMerchantActivitiesList2(lyMerchantActivities);
    }

    /**
     * 新增商家活动
     * 
     * @param lyMerchantActivities 商家活动
     * @return 结果
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public int insertLyMerchantActivities(LyMerchantActivities lyMerchantActivities)
    {
        //整合rabbitmq
        // 发送消息到RabbitMQ
        LyMerchantActivities mess = new LyMerchantActivities();
        mess.setId(lyMerchantActivities.getId());
        mess.setTitle(lyMerchantActivities.getTitle());
        mess.setMid(lyMerchantActivities.getMid());
        mess.setTime(lyMerchantActivities.getTime());
        mess.setImg(lyMerchantActivities.getImg());
        mess.setContent(lyMerchantActivities.getContent());
        mess.setEndTime(lyMerchantActivities.getEndTime());
        mess.setTelephone(lyMerchantActivities.getTelephone());
        mess.setNum(lyMerchantActivities.getNum());
        mess.setSendStatus(lyMerchantActivities.getSendStatus());
        mess.setShenheStatus(lyMerchantActivities.getShenheStatus());
        mess.setStatus(lyMerchantActivities.getStatus());
        rabbitTemplate.convertAndSend("fanout_sms", "", mess);
        System.out.println(mess);
        //整合websocket

        //返回值到前端
        return lyMerchantActivitiesMapper.insertLyMerchantActivities(lyMerchantActivities);
    }


    /**
     * 修改商家活动
     * 
     * @param lyMerchantActivities 商家活动
     * @return 结果
     */
    @Override
    public int updateLyMerchantActivities(LyMerchantActivities lyMerchantActivities)
    {
        return lyMerchantActivitiesMapper.updateLyMerchantActivities(lyMerchantActivities);
    }

    @Override
    public int xiugaisendStatus(LyMerchantActivities lyMerchantActivities) {
        return lyMerchantActivitiesMapper.xiugaisendStatus(lyMerchantActivities);
    }

    /**
     * 批量删除商家活动
     * 
     * @param ids 需要删除的商家活动主键
     * @return 结果
     */
    @Override
    public int deleteLyMerchantActivitiesByIds(Long[] ids)
    {
        return lyMerchantActivitiesMapper.deleteLyMerchantActivitiesByIds(ids);
    }

    /**
     * 删除商家活动信息
     * 
     * @param id 商家活动主键
     * @return 结果
     */
    @Override
    public int deleteLyMerchantActivitiesById(Long id)
    {
        return lyMerchantActivitiesMapper.deleteLyMerchantActivitiesById(id);
    }
}
